<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/mall/merchant/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='dpmc'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="shopName" placeholder="<fmt:message key='qsrdpmc'/>" value="<c:if test='${params.shopName !=null}'>${params.shopName}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='lxr'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="realName" placeholder="<fmt:message key='qsrxm'/>" value="<c:if test='${params.realName !=null}'>${params.realName}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='lxrdh'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="mobile" placeholder="<fmt:message key='qsrlxrdh'/>" value="<c:if test='${params.mobile !=null}'>${params.mobile}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='sjzt1'/></label>
                        <div class="layui-input-inline">
                            <select name="mainType">
                                <option value="0" <c:if test="${params.mainType eq 0}">selected</c:if>><fmt:message key='qxz'/></option>
                                <option value="1" <c:if test="${params.mainType eq 1}">selected</c:if>><fmt:message key='qy1'/></option>
                                <option value="2" <c:if test="${params.mainType eq 2}">selected</c:if>><fmt:message key='gth'/></option>
                                <option value="3" <c:if test="${params.mainType eq 3}">selected</c:if>><fmt:message key='gr'/></option>
                            </select>
                        </div>
                    </div>

                    <!-- 需要排序的字段 -->
                    <input type="hidden" class="feijin-orderby" name="orderByGoodsNumber" id="orderByGoodsNumberParams" value="${params.orderByGoodsNumber}"/>
                    <input type="hidden" class="feijin-orderby" name="orderByTotalOrderAmount" id="orderByTotalOrderAmountParams" value="${params.orderByTotalOrderAmount}"/>
                    <input type="hidden" class="feijin-orderby" name="orderByTotalOrderNumber" id="orderByTotalOrderNumberParams" value="${params.orderByTotalOrderNumber}"/>
                    <input type="hidden" class="feijin-orderby" name="orderByMerchantEnterTime" id="orderByMerchantEnterTimeParams" value="${params.orderByMerchantEnterTime}"/>
                    <!-- 需要排序的字段 -->

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">
            <shiro:hasPermission name="merchant:create">
                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='tjsj'/></a>
            </shiro:hasPermission>
            <shiro:hasPermission name="merchant:enables">
                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="enables"><i class="layui-icon">&#xe605;</i> <fmt:message key='plqy'/></a>
            </shiro:hasPermission>
            <shiro:hasPermission name="merchant:disables">
                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger" id="disables"><i class="layui-icon">&#x1006;</i> <fmt:message key='pljy'/></a>
            </shiro:hasPermission>

            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th width="5%"><input id="checkboxs" type="checkbox" lay-ignore lay-skin="primary"/></th>
                    <th><fmt:message key='zh'/></th>
                    <th><fmt:message key='dpmc'/></th>
                    <th><fmt:message key='ztlx'/></th>
                    <th><fmt:message key='lxr'/></th>
                    <th><fmt:message key='sjhm'/></th>
                    <th id="orderByMerchantEnterTime">
                        <span><fmt:message key='rzsj'/></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderByMerchantEnterTime}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx1'/>"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx'/>"></i></span>
                    </th>
                    <th id="orderByGoodsNumber">
                        <span><fmt:message key='zssps'/></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderByGoodsNumber}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx1'/>"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx'/>"></i></span>
                    </th>
                    <th id="orderByTotalOrderAmount">
                        <span><fmt:message key='zcjje'/></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderByTotalOrderAmount}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx1'/>"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx'/>"></i></span>
                    </th>
                    <th id="orderByTotalOrderNumber">
                        <span><fmt:message key='zcjbs'/></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderByTotalOrderNumber}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx1'/>"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx'/>"></i></span>
                    </th>
                    <th><fmt:message key='sjzt2'/></th>
                    <th><fmt:message key='cz'/></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td><input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/></td>
                        <td>${item.username }</td>
                        <td>${item.shopName }<c:if test="${item.selfSupport eq 1}"><b style="color:green"><fmt:message key='zysj'/></b></c:if></td>
                        <td>
                            <c:choose>
                                <c:when test="${item.mainType eq 1}"><fmt:message key='qy1'/></c:when>
                                <c:when test="${item.mainType eq 2}"><fmt:message key='gth'/></c:when>
                                <c:when test="${item.mainType eq 3}"><fmt:message key='gr'/></c:when>
                            </c:choose>
                        </td>
                        <td>${item.realName }</td>
                        <td>${item.mobile}</td>
                        <td><fmt:formatDate value="${item.merchantEnterTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                        <td>${item.goodsNumber}</td>
                        <td><fmt:formatNumber value="${item.totalOrderAmount}" type="CURRENCY"/></td>
                        <td>${item.totalOrderNumber}</td>
                        <td>
                            <c:choose>
                                <c:when test="${item.accountNonLocked}"><b style="color:green;"><fmt:message key='qy'/></b></c:when>
                                <c:otherwise><b style="color:red;"><fmt:message key='jy'/></b></c:otherwise>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">

                                <shiro:hasPermission name="merchant:detail">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='ck'/></a>
                                </shiro:hasPermission>

                                <shiro:hasPermission name="merchant:modify">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-modify"><fmt:message key='bj'/></a>
                                </shiro:hasPermission>

                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs layui-btn-danger feijin-reset"><fmt:message key='csmm'/></a>

                                <c:choose>
                                    <c:when test="${item.accountNonLocked}">
                                        <shiro:hasPermission name="merchant:disabled">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-locked"><fmt:message key='jy'/></a>
                                        </shiro:hasPermission>
                                    </c:when>
                                    <c:otherwise>
                                        <shiro:hasPermission name="merchant:enabled">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-unlocked"><fmt:message key='qy'/></a>
                                        </shiro:hasPermission>
                                    </c:otherwise>
                                </c:choose>
                                <c:choose>
                                    <c:when test="${item.selfSupport eq 0}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-selfSupport"><fmt:message key='swzy'/></a>
                                    </c:when>
                                    <c:otherwise>
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs layui-btn-danger feijin-cancelSelfSupport"><fmt:message key='qxzy'/></a>
                                    </c:otherwise>
                                </c:choose>

                                <a href="javascript:void(0);" data-url="/pages/index/shop/shop?id=${item.id}" class="layui-btn layui-btn-xs copy-url"><fmt:message key='fzurl'/></a>

                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //全选反选
        $("#checkboxs").click(function () {
            if (this.checked) {
                $(".feijin-check:checkbox").prop("checked", true);
            } else {
                $(".feijin-check:checkbox").prop("checked", false);
            }
        });

        //查看详情
        $(".feijin-detail").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='cksj'/>'
                , content: '${web_domain}/mall/merchant/' + id + '/detail'
                , maxmin: true
                , area: ['95%', '95%']
                , btn: ['<fmt:message key='fh'/>']
            });
        });

        //重置密码
        $(".feijin-reset").click(function () {

            var id = $(this).attr("data-id");

            layer.confirm("<fmt:message key='qrczgsjmmw'/>", function () {

                $.ajax({
                    type: "post",
                    url: "${web_domain}/mall/merchant/resetPassword",
                    dataType: "json",
                    data: {
                        "id": id,
                        "_method": "put"
                    },
                    success: function (result) {
                        if (result.status) {
                            layer.msg('<fmt:message key='czcg'/>');
                            window.setTimeout("javascript:location.reload();", 2000);
                        } else {
                            layer.msg(data.message);
                        }
                    }
                });
            });

        });

        //批量启用账号
        $("#enables").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length == 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.open({
                content: '<fmt:message key='qryjxzdsjqbqym?'/>'
                , btn: ['<fmt:message key='qy'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    $.ajax({
                        url: "${web_domain}/mall/merchant/enables",
                        type: "post",
                        dataType: "json",
                        data: {
                            "ids": ids.join(";"),
                            "_method": "put"
                        },
                        success: function (result) {
                            if (result.status) {
                                location.reload();
                            }
                        }
                    });
                }
            });
        });

        //批量禁用账号
        $("#disables").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length == 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.open({
                content: '<fmt:message key='qryjxzdsjqbjym?'/>'
                , btn: ['<fmt:message key='jy'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    $.ajax({
                        url: "${web_domain}/mall/merchant/disables",
                        type: "post",
                        dataType: "json",
                        data: {
                            "ids": ids.join(";"),
                            "_method": "put"
                        },
                        success: function (result) {
                            if (result.status) {
                                location.reload();
                            }
                        }
                    });
                }
            });
        });

        //添加商家
        $("#add").click(function () {
            layer.open({
                type: 2
                , title: '<fmt:message key='tjsj'/>'
                , content: '${web_domain}/mall/merchant/create'
                , maxmin: true
                , area: ['95%', '95%']
                , btn: ['<fmt:message key='qd1'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });


        $(".copy-url").click(function () {
            var url = $(this).attr("data-url");
            var transfer = $("<input type='text' id='copy_text'>");
            $("body").append(transfer);
            transfer.val(url)
            transfer.focus();
            transfer.select();
            document.execCommand('Copy', false, null);
            $('#copy_text').remove();
            layer.msg("<fmt:message key='fzcg'/>");
        });

        //编辑
        $(".feijin-modify").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='bjsjxx'/>'
                , content: '${web_domain}/mall/merchant/' + id + '/modify'
                , maxmin: true
                , area: ['95%', '95%']
                , btn: ['<fmt:message key='qd1'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //禁用
        $(".feijin-locked").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='jyzh'/>',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='jyhgzhjwfdl,qrjyzhm?'/></span>',
                    btn: ['<fmt:message key='jy'/>', '<fmt:message key='qx'/>'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/mall/merchant/disable",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        //启用
        $(".feijin-unlocked").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='qyzh'/>',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qdhfgzhzcsym?'/></span>',
                    btn: ['<fmt:message key='qy'/>', '<fmt:message key='qx'/>'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/mall/merchant/enabled",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        //设为自营
        $(".feijin-selfSupport").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='swzy'/>',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrszgsjwzysjm?'/></span>',
                    btn: ['<fmt:message key='qd1'/>', '<fmt:message key='qx'/>'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/mall/merchant/selfSupport",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        //取消设为自营
        $(".feijin-cancelSelfSupport").click(function () {
            var id = $(this).attr("data-id");
            layui.use('layer', function () {
                var layer = layui.layer;
                layer.open({
                    type: 0,
                    title: '<fmt:message key='swzy'/>',//自定义标题样式
                    border: [0],
                    content: '<span class="orange"><fmt:message key='qrszgsjwzysjm?'/></span>',
                    btn: ['<fmt:message key='qx1'/>', '<fmt:message key='qx'/>'],
                    yes: function () {
                        $.ajax({
                            type: "post",
                            url: "${web_domain}/mall/merchant/cancelSelfSupport",
                            dataType: "json",
                            data: {
                                "id": id,
                                "_method": "put"
                            },
                            success: function (data) {
                                location.reload();
                            }
                        });
                    },
                    no: function () {
                        layer.close(index);
                    }
                });
            });
        });

        //按商家入驻时间排序
        $("#orderByMerchantEnterTime").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByMerchantEnterTime}";

            if (orderBy == "asc") {
                $("#orderByMerchantEnterTimeParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByMerchantEnterTimeParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByMerchantEnterTimeParams").attr("value", "desc");
                $("#search").click();
                return;
            }
        });

        //按总订单笔数排序
        $("#orderByTotalOrderNumber").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByTotalOrderNumber}";

            if (orderBy == "asc") {
                $("#orderByTotalOrderNumberParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByTotalOrderNumberParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByTotalOrderNumberParams").attr("value", "desc");
                $("#search").click();
                return;
            }

        });

        //按总订单金额排序
        $("#orderByTotalOrderAmount").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByTotalOrderAmount}";

            if (orderBy == "asc") {
                $("#orderByTotalOrderAmountParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByTotalOrderAmountParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByTotalOrderAmountParams").attr("value", "desc");
                $("#search").click();
                return;
            }

        });

        //按在售商品数量排序
        $("#orderByGoodsNumber").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByGoodsNumber}";

            if (orderBy == "asc") {
                $("#orderByGoodsNumberParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByGoodsNumberParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByGoodsNumberParams").attr("value", "desc");
                $("#search").click();
                return;
            }

        });

    });
</script>
</body>
</fmt:bundle>
</html>
